// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: donggu

#pragma once

#include <map>
#include <memory>
#include <string>
#include <vector>

#include <simdjson.h>

// internal
#include "coin2/exchange/base/feed/processor.h"
#include "coin2/exchange/base/market/enums.h"
#include "coin2/exchange/di/constant.h"
#include "coin2/exchange/huobi/feed_v1/processor.h"  // reuse huobi.spot's HuobiChannel

namespace coin2::exchange::huobi_futures::feed_v1 {
namespace impl {
using coin2::exchange::base::executor::TopicRecordPacket;
using namespace coin2::exchange::base::symbology;
class HuobiFuturesFeedProcessor : public base::feed::FeedParsingProcessor {
 public:
  explicit HuobiFuturesFeedProcessor(
      const std::string& system_name,
      const coin2::exchange::di::ConstantInjection& ci,
      const feed::RawParserConfig& config,
      const MarketExchangeApi& mea)
      : FeedParsingProcessor(
            system_name,
            mea,
            ci,
            config,
            "cc/coin2/exchange/huobi_futures/feed_v1/schema.json"),
        publish_bbo_book_only_(config.publish_bbo_book_only()) {}

  void OnTopicRecord(const base::executor::TopicRecordPacket& packet) override;
 private:
  std::vector<std::string> RegisteredFuturesOfCurrency(std::string_view native_symbol);
  const bool publish_bbo_book_only_;
  simdjson::dom::parser parser_;

  struct FeedTopicStat {
    bool bbo_received = false;
    bool update_received = false;
  };
  std::unordered_map<std::string, FeedTopicStat> topic_stat_;
};
}  // namespace impl
using impl::HuobiFuturesFeedProcessor;
}  // namespace coin2::exchange::huobi_futures::feed_v1
